﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;
using AutoBackupDatabase.ENT;
using System.Data;
using System.Data.SqlClient;

namespace AutoBackupDatabase.DAL
{
    public class ITEMTYPEDAL
    {
        private DbConnection conn;
        public ITEMTYPEDAL()
        {
            conn = new DbConnection();
        }

        public List<ITEMTYPEENT> GET_ITEMTYPE_ALL()
        {
            string query = string.Format("exec GET_ITEMTYPE_ALL ");
            DataTable ds = conn.executeGetQuery(query);
            List<ITEMTYPEENT> List = new List<ITEMTYPEENT>();
            foreach (DataRow item in ds.Rows)
            {
                ITEMTYPEENT itemtypeent = new ITEMTYPEENT();
                itemtypeent.ITEMTYPEID =int.Parse( item["ITEMTYPEID"].ToString());
                itemtypeent.ITEMTYPENAME = item["ITEMTYPENAME"].ToString();
                List.Add(itemtypeent);
            }
            return List;
        }
        public bool INSERTITEMTYPE(ITEMTYPEENT ent)
        {
            string query = "exec  INSERTITEMTYPE @ITEMTYPENAME";
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@ITEMTYPENAME", SqlDbType.NVarChar);
            sqlParameters[0].Value = Convert.ToString(ent.ITEMTYPENAME);
            return conn.executeInsertQuery(query, sqlParameters);
        }
        public bool UPDATEITEMTYPEBYITEMTYPEID(ITEMTYPEENT ent)
        {
            string query = "exec  UPDATEITEMTYPEBYITEMTYPEID @ITEMTYPEID,@ITEMTYPENAME";
            SqlParameter[] sqlParameters = new SqlParameter[2];
            sqlParameters[0] = new SqlParameter("@ITEMTYPEID", SqlDbType.VarChar);
            sqlParameters[0].Value = Convert.ToString(ent.ITEMTYPEID);
            sqlParameters[1] = new SqlParameter("@ITEMTYPENAME", SqlDbType.NVarChar);
            sqlParameters[1].Value = Convert.ToString(ent.ITEMTYPENAME);
            return conn.executeUpdateQuery(query, sqlParameters);
        }
        public bool DELTELEITEMTYPEBYITEMTYPEID(ITEMTYPEENT ent)
        {
            string query = "exec  DELTELEITEMTYPEBYITEMTYPEID @ITEMTYPEID";
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@ITEMTYPEID", SqlDbType.VarChar);
            sqlParameters[0].Value = Convert.ToString(ent.ITEMTYPEID);
            return conn.executeDeleteQuery(query, sqlParameters);
        }
    }
}
